package com.emperor.service.impl;

import com.emperor.dto.ApplyPolicyRequestDto;
import com.emperor.dto.TbVmTypeDto;
import com.emperor.dto.UpdateChannelRequestDto;
import com.emperor.dto.VmTypeDto;
import com.emperor.entity.ChannelList;
import com.emperor.entity.VendingMachine;
import com.emperor.entity.VmType;
import com.emperor.mapper.VmMapper;
import com.emperor.service.VmService;
import com.emperor.vo.BusinessTop10Vo;
import com.emperor.vo.ChannelListVo;
import com.emperor.vo.VmTypeVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.time.LocalDateTime;
import java.util.List;

@Service
public class VmServiceImpl implements VmService {

    @Autowired
    private VmMapper vmMapper;

    @Override
    public VmType findVmType(VmTypeDto vmTypeDto) {
        return vmMapper.findVmType(vmTypeDto);
    }

    @Override
    public List<ChannelListVo> findChannelList(String innerCode) {

        List<ChannelListVo> channelList = vmMapper.findChannelList(innerCode);

        System.out.println(channelList);
        return channelList;
    }

    @Override
    public VmTypeVo addVm(TbVmTypeDto dto) {
        VendingMachine vm = new VendingMachine();
        BeanUtils.copyProperties(dto, vm);

        VmTypeVo build = VmTypeVo.builder().vmRow(10).vmCol(6)
                .name("果蔬2").channelMaxCapacity(20).model("GS001")
                .build();

        vm.setUpdateTime(LocalDateTime.now());
        vmMapper.addVm(build);
        vmMapper.addVmMachine(vm);
        return build;
    }

    @Override
    public void updateVm(Integer id, Integer nodeId) {
        vmMapper.updateVm(id, nodeId);
    }

    @Override
    public List<BusinessTop10Vo>  businessTop10(Integer businessId) {

        return  vmMapper.businessTop10(businessId);
    }

    @Override
    public void channelConfig(UpdateChannelRequestDto dto) {
        vmMapper.channelConfig(dto);
    }

    @Override
    public void applyPolicy(ApplyPolicyRequestDto dto) {
        vmMapper.applyPolicy(dto);
    }
}
